#encoding=utf-8

import datetime
import time
import urllib
import ujson

from django.contrib import admin,messages
from django.db.models import Count, Max, F, Sum
from django.db.models.query import QuerySet
from django.utils.safestring import mark_safe
from django.utils.html import format_html
from django.contrib.auth.views import login
from django.contrib.auth.models import User
from gm_site import settings
import webconfig,fun

from websys.models import (
    ServerInfo,WhiteList,BlackList,NewInfo,ChatInfo,EmailInfo,PackInfo,PropInfo,Gift_Code,GiftCode
)
import MySQLdb
import xadmin
from xadmin.views.list import ResultRow, ResultItem
from websys.admin.AdminLoginForm import AdminAuthenticationForm
from xadmin.views import website
from django.http import HttpResponseRedirect


website.LoginView.login_form = AdminAuthenticationForm
# Register your models here.
from api import InterfaceFun

#获取多服务器
def getServers(obj):
    ser_arr=[]
    tmp_arr= obj.server.all()
    print '----------------',tmp_arr
    for ii_item in tmp_arr:
        ser_arr.append( ii_item.pf)
    return ser_arr

#服务器管理
class ServerInfoAdmin(object):
    list_display = ('pf','name','host','port',)
    search_fields = ('name','pf',)
    list_filter = ('pf',)
    list_exclude = ('id',)

    def get_media(self):
        # <div id="type-dialogBox"></div>
        media = super(ServerInfoAdmin, self).get_media()
        media.add_js((self.static('ButtonControl.js'),))
        return media

    def save_models(self):
        obj = self.new_obj
        obj.save()

    def delete_models(self, queryset):
        super(ServerInfoAdmin, self).delete_models(queryset)

#服务器白名单
class WhiteListAdmin(object):
    list_display = ('uids','server','start_time','end_time')
    search_fields = ('uids',)
    list_filter = ('create_date',)
    list_exclude = ('id',)

    # def get_media(self):
    #     # <div id="type-dialogBox"></div>
    #     media = super(WhiteListAdmin, self).get_media()
    #     media.add_js((self.static('ButtonControl.js'),))
    #     return media

    def save_models(self):
        obj = self.new_obj
        obj.save()

    def delete_models(self, queryset):
        super(WhiteListAdmin, self).delete_models(queryset)

class GiftCodeAdmin(object):
    if settings.which_game=='chengbao':
        list_display = ('serial_no','server_code','expired_utc','code','items','gift_type','activity_id','gift_num','create_time')
        search_fields = ('serial_no','gift_type','server_code')
        list_filter = ('serial_no','gift_type','create_time','activity_id')
        list_exclude = ('id','is_plat')
    else:
        list_display = ('serial_no','server_code', 'expired_utc', 'code', 'items', 'gift_type',  'gift_num','create_time')
        search_fields = ('gift_type', 'server_code')
        list_filter = ('gift_type', 'create_time',)
        list_exclude = ('id', 'is_plat','activity_id',)




#黑名单
class BlackListAdmin(object):
    list_display = ('uids', 'server', 'start_time', 'end_time','status','reason')
    search_fields = ('uids',)
    list_filter = ('create_date',)
    list_exclude = ('id',)
    fields=('uids','server','start_time','end_time','status','reason')

    # def get_media(self):
    #     # <div id="type-dialogBox"></div>
    #     media = super(WhiteListAdmin, self).get_media()
    #     media.add_js((self.static('ButtonControl.js'),))
    #     return media

    def save_models(self):
        obj = self.new_obj
        obj.operid=self.request.user.username
        obj.save()
        #接口是否成功
        # ser_arr=[]
        # tmp_arr= obj.server.all()
        # for ii_item in tmp_arr:
        #     ser_arr.append( ii_item.pf)
        ser_arr=getServers(obj)
        print '--BlackListAdmin--',ser_arr
        t_ok=0
        if obj.status==0:#封号
            t_ok=InterfaceFun.LOGIN_SWITCH_UID(ser_arr,0,obj.uids,fun.DateTimeToStamp(obj.end_time))
        else:
            t_ok=InterfaceFun.FORBID_SPEAK(ser_arr,obj.uids,fun.DateTimeToStamp(obj.end_time))
        if t_ok==0:
           messages.warning(self.request, '同步到服务器不成功，可2次修改')

    def delete_models(self, queryset):
        for ii_item in queryset:
            if ii_item.status==0:#封号
                InterfaceFun.LOGIN_SWITCH_UID(getServers(ii_item),1,ii_item.uids,-1)
            else:
                pass

        super(BlackListAdmin, self).delete_models(queryset)


#公告、跑马灯
class NewinfoAdmin(object):
    list_display = ('title', 'content', 'start_time', 'end_time','server','orderid')
    search_fields = ('title',)
    list_filter = ('create_date','orderid')
    list_exclude = ('id',)

    # def get_media(self):
    #     # <div id="type-dialogBox"></div>
    #     media = super(WhiteListAdmin, self).get_media()
    #     media.add_js((self.static('ButtonControl.js'),))
    #     return media

    def save_models(self):
        request = self.request
        obj = self.new_obj
        # print(obj.start_time,type(obj.start_time),fun.DateTimeToStamp(obj.start_time))
        # print '\n'.join(['%s:%s' % item for item in obj.__dict__.items()])

        tid=obj.id;
        if not tid:#新增，最大的id
            tmp_arr=NewInfo.objects.all().order_by('-id')
            if len(tmp_arr)==0:
                tid=1
            else:
                tid=tmp_arr[0].id+1

        #ni=NewInfo()
        #print obj.server#.all()
        obj.save()
        #return
        #接口是否成功
        # ser_arr=[]
        # tmp_arr= obj.server.all()
        # for ii_item in tmp_arr:
        #     ser_arr.append( ii_item.pf)
        ser_arr=getServers(obj)
        print '--NewAdmin--',ser_arr
        if InterfaceFun.ADDSCROLLNOTES(ser_arr,obj.content,obj.id,fun.DateTimeToStamp(obj.start_time),fun.DateTimeToStamp(obj.end_time),obj.orderid)==0:
           messages.warning(request, '同步到服务器不成功，可2次修改')

    def delete_models(self, queryset):
        super(NewinfoAdmin, self).delete_models(queryset)

#聊天框
class ChatInfoAdmin(object):
    list_display = ('title', 'content', 'start_time', 'end_time','server','intervals')
    search_fields = ('title',)
    list_filter = ('create_date','intervals')
    list_exclude = ('id',)

    # def get_media(self):
    #     # <div id="type-dialogBox"></div>
    #     media = super(WhiteListAdmin, self).get_media()
    #     media.add_js((self.static('ButtonControl.js'),))
    #     return media

    def save_models(self):
        obj = self.new_obj
        obj.save()

    def delete_models(self, queryset):
        super(ChatInfoAdmin, self).delete_models(queryset)

# #邮件
# class EmailInfoAdmin(object):
#     list_display = ('uids','title', 'content','server')
#     search_fields = ('uids',)
#     list_filter = ('create_date',)
#     list_exclude = ('id',)
#
#     # def get_media(self):
#     #     # <div id="type-dialogBox"></div>
#     #     media = super(WhiteListAdmin, self).get_media()
#     #     media.add_js((self.static('ButtonControl.js'),))
#     #     return media
#
#     def save_models(self):
#         request = self.request
#         obj = self.new_obj
#         tid=obj.id;
#         if not tid:#新增，最大的id
#             tmp_arr=EmailInfo.objects.all().order_by('-id')
#             if len(tmp_arr)==0:
#                 tid=1
#             else:
#                 tid=tmp_arr[0].id+1
#
#         obj.save()
#         ser_arr = getServers(obj)
#         print '--NewAdmin--', ser_arr
#         if InterfaceFun.SENDMAIL(ser_arr, obj.uids,obj.content) == 0:
#             messages.warning(request, '同步到服务器不成功，可2次修改')
#
#     def delete_models(self, queryset):
#         super(EmailInfoAdmin, self).delete_models(queryset)

#礼包
class PackInfoAdmin(object):
    list_display = ('uids','packid','server')
    search_fields = ('uids','packid')
    list_filter = ('create_date',)
    list_exclude = ('id',)

    # def get_media(self):
    #     # <div id="type-dialogBox"></div>
    #     media = super(WhiteListAdmin, self).get_media()
    #     media.add_js((self.static('ButtonControl.js'),))
    #     return media

    def save_models(self):
        obj = self.new_obj
        obj.save()

    def delete_models(self, queryset):
        super(PackInfoAdmin, self).delete_models(queryset)
# #道具
# class PropInfoAdmin(object):
#     list_display = ('uids','propid','server','amount')
#     search_fields = ('uids','propid',)
#     list_filter = ('create_date',)
#     list_exclude = ('id',)
#
#     # def get_media(self):
#     #     # <div id="type-dialogBox"></div>
#     #     media = super(WhiteListAdmin, self).get_media()
#     #     media.add_js((self.static('ButtonControl.js'),))
#     #     return media
#
#     def save_models(self):
#         obj = self.new_obj
#         obj.save()
#
#     def delete_models(self, queryset):
#         super(PropInfoAdmin, self).delete_models(queryset)
#全局配置

def getserver():
    lists=[]
    try:
        conn = MySQLdb.connect(host=webconfig.con_db['host'], port=webconfig.con_db['port'],
                               user=webconfig.con_db['user'], passwd=webconfig.con_db['password'],
                               db=webconfig.con_db['database'],charset='utf8')
        cursor = conn.cursor()
        sql="SELECT * FROM t_servers "

        cursor.execute(sql)
        data = cursor.fetchall()
        server_list =[]
        for i in data:
            ser_dic={}
            ser_dic['server_id']=i[0]
            ser_dic['pf']=i[1]
            ser_dic['name']=i[2]
            ser_dic['host']=i[3]
            ser_dic['port']=i[4]
            ser_dic['status']=1
            server_list.append(ser_dic)
        conn.close()
        return server_list
    except:
        return lists



from xadmin import views
class BaseSetting(object):
    enable_themes = True
    use_bootswatch = True

class AdminSettings(object):
    # 设置base_site.html的Title
    site_title = '游戏管理系统'
    # 设置base_site.html的Footer
    site_footer = 'Winhong Inc.'
    menu_style = 'default'
    #xadmin.site.

    # 菜单设置
    def get_site_menu(self):
        all_menu = {'menzhan': (
            {'title': '数据统计', 'perm': self.get_model_perm(NewInfo, 'change'), 'menus': (
                {'title': '核心数据', 'url': '/xadmin/reportdata/core'},
                {'title': '充值信息', 'url': '/xadmin/reportdata/recharge'},
                {'title': '充值排行', 'url': '/xadmin/reportdata/rank_recharge'},
                {'title': '在线分析', 'url': '/xadmin/reportdata/online'},
                {'title': '道具购买', 'url': '/xadmin/reportdata/props'},
                {'title': '新手流失', 'url': '/xadmin/reportdata/newloss'},
                {'title': '等级数据生成', 'url': '/xadmin/otherdata/level_data'},
                # {'title': '加载流失', 'url': '/xadmin/reportdata/loadloss'},
            )},
            {'title': '信息管理', 'perm': self.get_model_perm(NewInfo, 'change'), 'menus': (
                {'title': '玩家查询', 'url': '/xadmin/userdata/vague'},
                {'title': '信息查询&修改', 'url': '/xadmin/userdata/info'},
                # {'title': '付费任务完成率', 'url': '/xadmin/userdata/task'},
                {'title': '阶段统计&排行', 'url': '/xadmin/userdata/system'},
                # {'title': '资源排行', 'url': '/xadmin/userdata/resource'},
            )},
            {'title': '道具管理', 'perm': self.get_model_perm(NewInfo, 'change'), 'menus': (
                # {'title': '礼包发送', 'url':'/xadmin/systemdata/bag'},
                {'title': '道具删除', 'url': '/xadmin/userdata/prop'},
                {'title': '礼物码生成', 'url': '/xadmin/otherdata/gift_code'},
                {'title': '礼物码', 'url': self.get_model_url(Gift_Code, 'changelist')},
                {'title': '充值', 'url': '/xadmin/userdata/recharge_mz'},

            )},
            {'title': '通告管理', 'perm': self.get_model_perm(NewInfo, 'change'), 'menus': (
                {'title': '公告', 'url': '/xadmin/systemdata/news'},
                {'title': '登录公告', 'url': '/xadmin/systemdata/login_news'},
                {'title': '聊天框', 'url': '/xadmin/systemdata/chat'},
                {'title': '邮件', 'url': '/xadmin/otherdata/email'},
            )},
            {'title': '黑名单&禁言管理', 'perm': self.get_model_perm(NewInfo, 'change'), 'menus': (
                {'title': '封号', 'url': '/xadmin/otherdata/forbid'},
                {'title': '禁言', 'url': '/xadmin/otherdata/speak'},
            )},
            {'title': '服务器管理', 'perm': self.get_model_perm(NewInfo, 'change'), 'menus': (
                {'title': '白名单', 'url': '/xadmin/systemdata/white'},
                {'title': '服务器', 'url': '/xadmin/systemdata/server'},
            )},
        ),

            'chengbao': (
                {'title': '数据统计', 'perm': self.get_model_perm(NewInfo, 'change'), 'menus': (
                    {'title': '核心数据', 'url': '/xadmin/reportdata/core'},
                    {'title': '充值信息', 'url': '/xadmin/cbyx_otherdata/recharge' },
                    {'title': '排行榜', 'url': '/xadmin/cbyx_userdata/ranks'},
                    {'title': '同时在线', 'url': '/xadmin/reportdata/online'},
                    #{'title': '道具购买', 'url': '/xadmin/reportdata/props'},
                    #{'title': '新手流失', 'url': '/xadmin/reportdata/newloss'},
                    {'title': '关卡流失', 'url': '/xadmin/cbyx_userdata/stage_lose'},
                    {'title': '加载流失', 'url': '/xadmin/cbyx_userdata/loading_lose'},
                )},
                {'title': '信息管理', 'perm': self.get_model_perm(NewInfo, 'change'), 'menus': (
                    #{'title': '玩家查询', 'url': '/xadmin/userdata/vague'},
                    {'title': '信息查询', 'url': '/xadmin/cbyx_userdata/info'},
                    {'title': '玩家信息修改', 'url': '/xadmin/cbyx_userdata/change'},
                    {'title': '数据生成', 'url': '/xadmin/cbyx_otherdata/get_data'},
                    # {'title': '付费任务完成率', 'url': '/xadmin/userdata/task'},
                    #{'title': '阶段统计&排行', 'url': '/xadmin/userdata/system'},
                    # {'title': '资源排行', 'url': '/xadmin/userdata/resource'},
                )},
                {'title': '道具管理', 'perm': self.get_model_perm(NewInfo, 'change'), 'menus': (
                    # {'title': '礼包发送', 'url':'/xadmin/systemdata/bag'},
                    {'title': '礼物码生成', 'url': '/xadmin/cbyx_otherdata/gift_code'},
                    {'title': '礼物码', 'url':self.get_model_url(Gift_Code, 'changelist')},
                    {'title': '道具&物品发送', 'url': '/xadmin/cbyx_userdata/send_prop'},
                    {'title': '充值', 'url': '/xadmin/cbyx_userdata/re_recharge'},

                )},
                {'title': '通告管理', 'perm': self.get_model_perm(NewInfo, 'change'), 'menus': (
                    {'title': '滚动公告', 'url': '/xadmin/cbyx_systemdata/news'},
                    {'title': '登录公告', 'url': '/xadmin/cbyx_systemdata/login_news'},
                    #{'title': '聊天框', 'url': '/xadmin/systemdata/chat'},
                    {'title': '邮件', 'url': '/xadmin/cbyx_systemdata/email'},
                    {'title': '玩家回复', 'url': '/xadmin/cbyx_otherdata/reply'},
                )},
                {'title': '黑名单&禁言管理', 'perm': self.get_model_perm(NewInfo, 'change'), 'menus': (
                    {'title': '封号', 'url': '/xadmin/cbyx_otherdata/forbid'},
                    {'title': '禁言', 'url': '/xadmin/cbyx_otherdata/speak'},
                    {'title': '黑名单', 'url': '/xadmin/cbyx_systemdata/black'},
                    {'title': '白名单', 'url': '/xadmin/cbyx_systemdata/white'},
                )},
                {'title': '服务器管理', 'perm': self.get_model_perm(NewInfo, 'change'), 'menus': (
                    #{'title': '白名单', 'url': '/xadmin/systemdata/white'},
                    {'title': '服务器', 'url': '/xadmin/cbyx_systemdata/server'},
                )},
            )
        }
        menu = all_menu[settings.which_game]
        #print(self.user,'_------***********')
        """``FAQ:如何定制系统菜单``\n
        用于给子类复写的方法，开发者可以在子类或 OptionClass 中复写该方法，返回自己定义的网站菜单。菜单的格式为::

            ({
                "title": "菜单标题", "perm": "权限标示",
                "icon": "图标的 css class", "url": "菜单url",
                "menus": [...]    # 子菜单项
            })

        菜单项的 ``perm`` 和 ``url`` 如果是基于 Model 的，可以使用 xadmin 提供的便利方法
        :meth:`BaseAdminObject.get_model_perm` 和 :meth:`BaseAdminObject.get_model_url`。举例说明创建菜单::

            class AdminSettings(object):

                def get_site_menu(self):
                    return (
                        {'title': '内容管理', 'perm': self.get_model_perm(Article, 'change'), 'menus':(
                            {'title': '游戏资料', 'icon': 'info-sign', 'url': self.get_model_url(Article, 'changelist') + '?_rel_categories__id__exact=2'},
                            {'title': '网站文章', 'icon': 'file', 'url': self.get_model_url(Article, 'changelist') + '?_rel_categories__id__exact=1'},
                        )},
                        {'title': '分类管理', 'perm': self.get_model_perm(Category, 'change'), 'menus':(
                            {'title': '主要分类', 'url': self.get_model_url(Category, 'changelist') + '?_p_parent__isnull=True'},
                            {'title': '游戏资料', 'url': self.get_model_url(Category, 'changelist') + '?_rel_parent__id__exact=2'},
                        )},
                    )

            site.register(CommAdminView, AdminSettings)

        """

        if self.user.is_superuser:
            SITE_CONFIG_MENU = menu

            if settings.which_game=='chengbao':
                server_info =ServerInfo.objects.all()
                h_server=[]
                for j in server_info:
                    h_server.append(int(j.server_id))
                server_list = getserver()
                if not server_info :
                    if server_list:
                        servers=ServerInfo()
                        for i in server_list:
                            servers.server_id=i['server_id']
                            servers.pf=i['pf']
                            servers.name=i['name']
                            servers.host=i['host']
                            servers.port=i['port']
                            servers.status=i['status']
                            servers.save()
                else:
                    if server_list:
                        for server in server_list:
                            #print server['server_id'],'---------------',h_server
                            if int(server['server_id']) not in h_server:
                                server_infos = ServerInfo()
                                server_infos.server_id=server['server_id']
                                server_infos.pf = server['pf']
                                server_infos.name = server['name']
                                server_infos.host = server['host']
                                server_infos.port = server['port']
                                server_infos.status = server['status']
                                server_infos.save()
            # SITE_CONFIG_MENU= (
            #             {'title': '数据统计', 'perm': self.get_model_perm(NewInfo, 'change'), 'menus':(
            #                 {'title': '核心数据', 'url': '/xadmin/reportdata/core'},
            #                 {'title': '充值信息', 'url': '/xadmin/reportdata/recharge'},
            #                 {'title': '同时在线', 'url': '/xadmin/reportdata/online'},
            #                 {'title': '道具购买', 'url': '/xadmin/reportdata/props'},
            #                 {'title': '新手流失', 'url': '/xadmin/reportdata/newloss'},
            #                 #{'title': '加载流失', 'url': '/xadmin/reportdata/loadloss'},
            #             )},
            #             {'title': '信息管理', 'perm': self.get_model_perm(NewInfo, 'change'), 'menus': (
            #                 {'title': '玩家查询', 'url': '/xadmin/userdata/vague'},
            #                 {'title': '信息查询&修改', 'url': '/xadmin/userdata/info'},
            #                 #{'title': '付费任务完成率', 'url': '/xadmin/userdata/task'},
            #                 {'title': '阶段统计&排行', 'url': '/xadmin/userdata/system'},
            #                 #{'title': '资源排行', 'url': '/xadmin/userdata/resource'},
            #             )},
            #             {'title': '道具管理', 'perm': self.get_model_perm(NewInfo, 'change'), 'menus': (
            #                 #{'title': '礼包发送', 'url':'/xadmin/systemdata/bag'},
            #                 {'title': '道具删除', 'url': '/xadmin/userdata/prop'},
            #
            #             )},
            #             {'title': '通告管理', 'perm': self.get_model_perm(NewInfo, 'change'), 'menus': (
            #                 {'title': '公告', 'url': '/xadmin/systemdata/news'},
            #                 {'title': '聊天框', 'url':'/xadmin/systemdata/chat'},
            #                 {'title': '邮件', 'url': '/xadmin/otherdata/email'},
            #             )},
            #             {'title': '黑名单&禁言管理', 'perm': self.get_model_perm(NewInfo, 'change'), 'menus': (
            #                 {'title': '封号', 'url': '/xadmin/otherdata/forbid'},
            #                 {'title': '禁言', 'url': '/xadmin/otherdata/speak'},
            #             )},
            #             {'title': '服务器管理', 'perm': self.get_model_perm(NewInfo, 'change'), 'menus': (
            #                 {'title': '白名单', 'url': '/xadmin/systemdata/white'},
            #                 {'title': '服务器', 'url':  '/xadmin/systemdata/server'},
            #             )},
            #         )
            # try:
            #     if(xadmin.site._registry.has_key(AgentInfo)):
            #         xadmin.site.unregister(AgentInfo)
            #     if(xadmin.site._registry.has_key(UserInfo)):
            #         xadmin.site.unregister(UserInfo)
            #     if(xadmin.site._registry.has_key(AgentBank)):
            #         xadmin.site.unregister(AgentBank)
            # except:
            #     pass
        else:
            #menu = all_menu[settings.which_game]

            all_else_menu={
                 'chengbao':(
                {'title': '数据统计', 'perm': self.get_model_perm(NewInfo, 'change'), 'menus': (
                    # {'title': '核心数据', 'url': '/xadmin/reportdata/core'},
                    {'title': '充值信息', 'url': '/xadmin/cbyx_otherdata/recharge'},
                    {'title': '排行榜', 'url': '/xadmin/cbyx_userdata/ranks'},
                    {'title': '同时在线', 'url': '/xadmin/reportdata/online','perm': self.get_model_perm(NewInfo, 'delete')},
                    # {'title': '道具购买', 'url': '/xadmin/reportdata/props'},
                    # {'title': '新手流失', 'url': '/xadmin/reportdata/newloss'},
                    {'title': '关卡流失', 'url': '/xadmin/cbyx_userdata/stage_lose','perm': self.get_model_perm(BlackList, 'view')},
                    {'title': '加载流失', 'url': '/xadmin/cbyx_userdata/loading_lose','perm': self.get_model_perm(BlackList, 'view')},
                )},
                {'title': '信息管理', 'perm': self.get_model_perm(NewInfo, 'change'), 'menus': (
                    # {'title': '玩家查询', 'url': '/xadmin/userdata/vague'},
                    {'title': '信息查询', 'url': '/xadmin/cbyx_userdata/info'},
                    #{'title': '玩家信息修改', 'url': '/xadmin/cbyx_userdata/change'},
                    # {'title': '付费任务完成率', 'url': '/xadmin/userdata/task'},
                    # {'title': '阶段统计&排行', 'url': '/xadmin/userdata/system'},
                    # {'title': '资源排行', 'url': '/xadmin/userdata/resource'},
                )},
                {'title': '道具管理', 'perm': self.get_model_perm(NewInfo, 'delete'), 'menus': (
                    # {'title': '礼包发送', 'url':'/xadmin/systemdata/bag'},
                    {'title': '礼物码生成', 'url': '/xadmin/cbyx_otherdata/gift_code'},
                    {'title': '礼物码', 'url': self.get_model_url(Gift_Code, 'changelist')},
                    {'title': '道具&物品发送', 'url': '/xadmin/cbyx_userdata/send_prop','perm': self.get_model_perm(GiftCode, 'view')},
                    {'title': '充值', 'url': '/xadmin/cbyx_userdata/re_recharge','perm': self.get_model_perm(GiftCode, 'view')},

                )},
                {'title': '通告管理', 'perm': self.get_model_perm(NewInfo, 'change'), 'menus': (
                    {'title': '滚动公告', 'url': '/xadmin/cbyx_systemdata/news'},
                    {'title': '登录公告', 'url': '/xadmin/cbyx_systemdata/login_news','perm': self.get_model_perm(NewInfo, 'delete')},
                    # {'title': '聊天框', 'url': '/xadmin/systemdata/chat'},
                    {'title': '邮件', 'url': '/xadmin/cbyx_systemdata/email','perm': self.get_model_perm(GiftCode, 'change')},
                    {'title': '玩家回复', 'url': '/xadmin/cbyx_otherdata/reply'},
                )},
                {'title': '黑名单&禁言管理', 'menus': (
                    {'title': '封号', 'url': '/xadmin/cbyx_otherdata/forbid','perm': self.get_model_perm(NewInfo, 'change'),},
                    {'title': '禁言', 'url': '/xadmin/cbyx_otherdata/speak','perm': self.get_model_perm(NewInfo, 'change'),},
                    {'title': '黑名单', 'url': '/xadmin/cbyx_systemdata/black','perm': self.get_model_perm(BlackList, 'view')},
                    {'title': '白名单', 'url': '/xadmin/cbyx_systemdata/white','perm': self.get_model_perm(BlackList, 'view')},
                )},
                {'title': '服务器管理', 'perm': self.get_model_perm(NewInfo, 'change'), 'menus': (
                    # {'title': '白名单', 'url': '/xadmin/systemdata/white'},
                    {'title': '服务器', 'url': '/xadmin/cbyx_systemdata/server','perm': self.get_model_perm(BlackList, 'view')},
                )},
                )
             }
            SITE_CONFIG_MENU=all_else_menu[settings.which_game]
            # #最后一级没有代理列表管理
            # #print(dir(self))
            # from django.contrib.sessions.models import Session
            # session_key=None
            # if('_auth_user_id' in self.request.session):
            #     session_key=self.request.session[ '_auth_user_id']
            # # print(self.request.session.keys(),'---session_key---',session_key)
            # # session = Session.objects.get(pk=session_key)
            # # print(session.session_data);                 # 返回session的存储（加密过）
            # # print(session.get_decoded());                # 返回session的数据结构（加过解码）
            # # print(session.expire_date);
            #
            # ag_arr=[]
            # if len(ag_arr)==0:#删除了，清了用户,跳转
            #     SITE_CONFIG_MENU= (
            #             {'title': '游戏管理', 'perm': self.get_model_perm(NewInfo, 'changelist'), 'menus':(
            #                 #{'title': '提现记录', 'url': self.get_model_url(WithdrawRecord, 'changelist') },
            #                 # {'title': '充值记录', 'url': self.get_model_url(UserRecharge, 'changelist') },
            #                 {'title': '充值报表', 'url': '/xadmin/agent/report'},
            #                 {'title': '金钻消耗统计', 'url': '/xadmin/gamereport/diamond'},
            #                 {'title': '在线统计', 'url': '/xadmin/gamereport/online'},
            #             )},
            #         )
            #     #SITE_CONFIG_MENU= ()
            # else:
            #     SITE_CONFIG_MENU= (
            #         {'title': '代理端管理', 'perm': self.get_model_perm(NewInfo, 'change'), 'menus':(
            #
            #                     #{'title': '代理局数统计', 'url': '/xadmin/agent_gather/gather'},
            #                     {'title': '我的信息', 'url': '/xadmin/agent/info'},
            #
            #                 )},
            #     )
            #     #return HttpResponseRedirect('/xadmin/logout/')  #跳转到index界面

        return  SITE_CONFIG_MENU
        #return None

#xadmin.site.register(views.BaseAdminView,BaseSetting)
#注册自定义的模板视图类
from websys.view import reportdata,userdata,otherdata,systemdata,cbyx_systemdata,cbyx_otherdata,cbyx_userdata

#注册model到页面
xadmin.site.register(ServerInfo, ServerInfoAdmin)
xadmin.site.register(Gift_Code, GiftCodeAdmin)
#xadmin.site.register(BlackList, BlackListAdmin)
#xadmin.site.register(NewInfo, NewinfoAdmin)
#xadmin.site.register(ChatInfo, ChatInfoAdmin)
#xadmin.site.register(EmailInfo,EmailInfoAdmin)
#xadmin.site.register(PropInfo, PropInfoAdmin)
#xadmin.site.register(PackInfo, PackInfoAdmin)


xadmin.site.register(views.CommAdminView,AdminSettings)


